#include <iostream>
using namespace std;

const int N = 100005;
int stk[N], tt;

int main()
{
    int n; cin >> n;
    while(n--)
    {
        int cur; cin >> cur;
        while(tt && stk[tt - 1] >= cur) --tt;
        if(tt) cout << stk[tt -  1] << ' ';
        else cout << -1 << ' ';
        stk[tt++] = cur;
    }
    return 0;
}
